package com.txd.mofa.adapter;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;

import androidx.recyclerview.widget.RecyclerView;

import com.txd.mofa.R;
import com.txd.mofa.bean.ShaixuanBean;

import java.util.ArrayList;
import java.util.List;

public class StaggeredGridAdapter extends RecyclerView.Adapter<StaggeredGridAdapter.LinearViewHolder> {

    private Context mContext;
    private AdapterView.OnItemClickListener mListener;
    private List<ShaixuanBean> list = new ArrayList<>();

    public StaggeredGridAdapter(Context mContext,List<ShaixuanBean> list) {
        this.mContext = mContext;
        this.list = list;
    }

    private  ItemOnclick itemOnclick;

    public interface ItemOnclick{
        void click(int pos);
        void shoucang(int pos);
        void qiehuan(int pos);
    }

    public void setItemOnclick(ItemOnclick itemOnclick) {
        this.itemOnclick = itemOnclick;
    }

    @Override
    public StaggeredGridAdapter.LinearViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new LinearViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_shouye, parent, false));
    }

    @Override
    public void onBindViewHolder(StaggeredGridAdapter.LinearViewHolder holder, int position) {

        if (position % 2 == 0) {
            holder.mImageView.setImageResource(R.mipmap.test2);
        } else {
            holder.mImageView.setImageResource(R.mipmap.test1);
        }

        Log.e("aaaaaaa",list.get(position).getPic()+"");

        holder.mImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                itemOnclick.click(position);
            }
        });

        holder.iv_qiehuan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                itemOnclick.qiehuan(position);
            }
        });

        holder.iv_sc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                itemOnclick.shoucang(position);
            }
        });


    }

    @Override
    public int getItemCount() {
        return 30;
    }

    class LinearViewHolder extends RecyclerView.ViewHolder {
        private ImageView mImageView,iv_sc,iv_qiehuan;

        public LinearViewHolder(View itemView) {
            super(itemView);
            mImageView = (ImageView) itemView.findViewById(R.id.iv);
            iv_sc = (ImageView) itemView.findViewById(R.id.iv_sc);
            iv_qiehuan = (ImageView) itemView.findViewById(R.id.iv_qiehuan);
        }
    }
}
